package com.itheima.clientAndService01;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class ServicerClass {
    public static void main(String[] args) throws IOException {
        //创建服务器ServerSocket对象，指定端口
        ServerSocket ss = new ServerSocket(10012);
        //将ServerSocket对象转换成Socket对象，Socket对象可以创建用于网络传输的字节输入或输出流
        Socket accept = ss.accept();
        //创建字节缓冲输入流，从网络上接收客户端发送过来的数据
        BufferedInputStream bis = new BufferedInputStream(accept.getInputStream());
        //创建字节缓冲输出流，保存上传的文件
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("day17_practice\\aaa\\a.jpg"));
        //保存发送过来的数据
        int b;
        while ((b = bis.read()) != -1) {
            bos.write(b);
        }

        //创建字符缓冲输出流对象，向客户端反馈数据上传信息
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        //写反馈
        String line = "上传成功！";
        bw.write(line);

        //释放资源
        bw.close();
        bis.close();
        ss.close();
        bos.close();
    }
}
